|
Download
FAQ History |
|
API
Search Feedback |
The Example JSP Pages
This chapter describes the tasks involved in defining tags. The chapter illustrates the tasks with excerpts from the JSP version of the Duke's Bookstore application discussed in The Example JSP Pages rewritten to take advantage of several new custom tags:
The last section in the chapter, Examples, describes several tags in detail: a simplified iteration tag and the set of tags in the
tutorial-templatetag library.The
tutorial-templatetag library defines a set of tags for creating an application template. The template is a JSP page with placeholders for the parts that need to change with each screen. Each of these placeholders is referred to as a parameter of the template. For example, a simple template could include a title parameter for the top of the generated screen and a body parameter to refer to a JSP page for the custom content of the screen. The template is created with a set of nested tags--definition,screen, andparameter--that are used to build a table of screen definitions for Duke's Bookstore and with aninserttag to insert parameters from the table into the screen.Figure 14-1 shows the flow of a request through the following Duke's Bookstore Web components:
template.jsp, which determines the structure of each screen. It uses theinserttag to compose a screen from subcomponents.screendefinitions.jsp, which defines the subcomponents used by each screen. All screens have the same banner, but different title and body content (specified by the JSP Page column in Table 12-1).Dispatcher, a servlet, which processes requests and forwards totemplate.jsp.
![]()
Figure 14-1 Request Flow Through Duke's Bookstore Components
The source code for the Duke's Bookstore application is located in the
<INSTALL>/j2eetutorial14/examples/web/bookstore3/directory created when you unzip the tutorial bundle (see About the Examples). A samplebookstore3.waris provided in<INSTALL>/j2eetutorial14/examples/web/provided-wars/. To build, package, deploy, and run the example:
- Build and package the bookstore common files as described in Duke's Bookstore Examples.
- In a terminal window, go to
<INSTALL>/j2eetutorial14/examples/bookstore3/.- Run
asantbuild. This target will spawn any necessary compilations and copy files to<INSTALL>/j2eetutorial14/examples/web/bookstore3/build/.- Start the J2EE application server.
- Perform all the operations described in Accessing Databases from Web Applications.
- Start
deploytool.- Create a Web application called
bookstore3.
- Select File
New
Web Application WAR.
- Select the Create New Stand-Alone WAR Module radio button.
- Click Browse.
- In the file chooser, navigate to
<INSTALL>/j2eetutorial14/examples/web/bookstore3/.- In the File Name field, enter
bookstore3.- Click Choose Module File.
- In the WAR Display Name field, enter
bookstore3.- Add Web application files and libraries.
- Click Edit.
- Add the application content. In the Edit Contents dialog, navigate to
<INSTALL>/j2eetutorial14/examples/web/bookstore3/build/. Select the JSP pagesbookstore.jsp,bookdetails.jsp,bookcatalog.jsp,bookshowcart.jsp,bookcashier.jsp,bookreceipt.jsp,bookordererror.jsp,Dispatcher.classand thedatabase,listeners, andtemplatedirectories and click Add. Click OK.- Add the shared bookstore library. Navigate to
<INSTALL>/j2eetutorial14/examples/build/web/bookstore/dist/. Selectbookstore.jarand Click Add.- Define the Web component.
- In the Deployment Setting frame, set the Context Root field value to
/bookstore3.- Add the aliases.
- Add the JSTL resource bundle basename context parameter.
- Set prelude for all JSP pages.
- Add a resource reference for the database.
- Select the Resource Refs tab.
- Click Add.
- Enter
jdbc/BookDBin the Coded Name field.- Accept the default type
javax.sql.DataSource.- Accept the default authorization
Container.- Accept the default selected
Shareable.- Enter
jdbc/BookDBin the JNDI name field of the Deployment setting for jdbc/BookDB frame.- Deploy the application.
- Open the bookstore URL
http://localhost:1024/bookstore3/bookstore.See Troubleshooting for help with diagnosing common problems.
|
Download
FAQ History |
|
API
Search Feedback |
All of the material in The J2EE 1.4 Tutorial is copyright-protected and may not be published in other works without express written permission from Sun Microsystems.